package net.jarang.sourcegen;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import net.jarang.support.db.FieldMapper;



public class TemplateInfo {
	private String domain;
	private String tableName;
	private String packageName;
	private String prefix;
	private String surffix;
	private String fileExtention;
	private List<String> importList = new ArrayList<String>();
	private List<String> implementsList = new ArrayList<String>();
	private String extendsStr;
	
	private boolean isTestCase;
	private boolean existDateType;
	
	private List<FieldMapper> fieldMappers;
	private List<FieldMapper> primaryKeyMappers;
	
	public String getFileName() {
		if ("jsp".equals(fileExtention)) {
			return getPrefix() + getSurffix() + "." + getFileExtention();
		} else {
			return getPrefix() + getDomain() + getSurffix() + "." + getFileExtention();
		}
	}
	
	public String getFilePath() {
		String packageName = StringUtils.replace(getPackageName(), ".", File.separator);

		if ("jsp".equals(fileExtention)) {
			return "output" + File.separator + "jsp" + File.separator + getDomainVariable() + File.separator + getFileName();
		} else {
			if (isTestCase) {
				return "output" + File.separator + "test" + File.separator + packageName + File.separator + getFileName();
			} else {
				return "output" + File.separator + "java" + File.separator + packageName + File.separator + getFileName();
			}
		}
	}
	
	public void addImportList(String importStr) {
		if (importList == null) {
			importList = new ArrayList<String>();
		}
		importList.add(importStr);
	}
	
	public void addImplementsList(String implementsStr) {
		if (implementsList == null) {
			implementsList = new ArrayList<String>();
		}
		implementsList.add(implementsStr);
	}
	
	public String getDomainVariable() {
		String tempStr = domain.substring(1, domain.length());
		String first = domain.substring(0, 1);
		return first.toLowerCase() + tempStr;
	}

	public String getPackageName() {
		return packageName;
	}
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}
	public String getDomain() {
		return domain;
	}
	public void setDomain(String domain) {
		this.domain = domain;
	}
	public String getPrefix() {
		return prefix;
	}
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
	public String getSurffix() {
		return surffix;
	}
	public void setSurffix(String surffix) {
		this.surffix = surffix;
	}
	public String getFileExtention() {
		return fileExtention;
	}
	public void setFileExtention(String fileExtention) {
		this.fileExtention = fileExtention;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public void setFieldMappers(List<FieldMapper> fieldMappers) {
		this.fieldMappers = fieldMappers;	
	}
	public List<FieldMapper> getFieldMappers() {
		return fieldMappers;
	}
	public void setPrimaryKeyMappers(List<FieldMapper> primaryKeyMappers) {
		this.primaryKeyMappers = primaryKeyMappers;
	}
	public List<FieldMapper> getPrimaryKeyMappers() {
		return primaryKeyMappers;
	}
	public boolean isTestCase() {
		return isTestCase;
	}
	public void setTestCase(boolean isTestCase) {
		this.isTestCase = isTestCase;
	}
	public List<String> getImportList() {
		return importList;
	}
	public void setImportList(List<String> importList) {
		this.importList = importList;
	}
	public List<String> getImplementsList() {
		return implementsList;
	}
	public void setImplementsList(List<String> implementsList) {
		this.implementsList = implementsList;
	}
	public String getExtendsStr() {
		return extendsStr;
	}
	public void setExtendsStr(String extendsStr) {
		this.extendsStr = extendsStr;
	}
	public void setExistDateType(boolean existDateType) {
		this.existDateType = existDateType;
	}
	public boolean isExistDateType() {
		return existDateType;
	}
}
